package net.tv90.bfmccoreqqbot.api;

import java.util.Random;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import static net.tv90.bfmccoreqqbot.api.WebSocketClientInitializer.client;

public class DefaultMessageSender implements MessageSender {

    private static final ExecutorService executorService = new ThreadPoolExecutor(
            1, 2, 120L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(3));

    public DefaultMessageSender() {
        super();
    }

    @Override
    public void sendMessage(String msg) {
        executorService.submit(() -> {
                    try {
                        Thread.sleep(3000 + new Random().nextInt(2000));
                        client.send(msg);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
        );
    }
}
